﻿using System;
using UnityEngine;

// Token: 0x0200015A RID: 346
[AddComponentMenu("RVP/C#/Effects/Vehicle Light", 3)]
[DisallowMultipleComponent]
public class VehicleLight : MonoBehaviour
{
	// Token: 0x06000642 RID: 1602 RVA: 0x00034946 File Offset: 0x00032B46
	private void Start()
	{
		this.rend = base.GetComponent<Renderer>();
		if (this.rend)
		{
			this.offMaterial = this.rend.sharedMaterial;
		}
		this.shatter = base.GetComponent<ShatterPart>();
	}

	// Token: 0x06000643 RID: 1603 RVA: 0x00034984 File Offset: 0x00032B84
	private void Update()
	{
		if (this.shatter)
		{
			this.shattered = this.shatter.shattered;
		}
		if (this.sharedLight && this.sharer)
		{
			this.sharedLight.enabled = (this.on && this.sharer.on && !this.shattered && !this.sharer.shattered);
		}
		if (this.targetLight && this.sharedLight && this.sharer)
		{
			this.targetLight.enabled = (!this.shattered && this.on && !this.sharedLight.enabled);
		}
		if (this.rend)
		{
			if (this.shattered)
			{
				if (this.shatter.brokenMaterial)
				{
					this.rend.sharedMaterial = this.shatter.brokenMaterial;
				}
				else
				{
					this.rend.sharedMaterial = ((!this.on && !this.halfOn) ? this.offMaterial : this.onMaterial);
				}
			}
			else
			{
				this.rend.sharedMaterial = ((!this.on && !this.halfOn) ? this.offMaterial : this.onMaterial);
			}
		}
	}

	// Token: 0x040009C4 RID: 2500
	private Renderer rend;

	// Token: 0x040009C5 RID: 2501
	private ShatterPart shatter;

	// Token: 0x040009C6 RID: 2502
	public bool on;

	// Token: 0x040009C7 RID: 2503
	[Tooltip("Example: a brake light would be half on when the night lights are on, and fully on when the brakes are pressed")]
	public bool halfOn;

	// Token: 0x040009C8 RID: 2504
	public Light targetLight;

	// Token: 0x040009C9 RID: 2505
	[Tooltip("A light shared with another vehicle light, will turn off if one of the lights break, then the unbroken light will turn on its target light")]
	public Light sharedLight;

	// Token: 0x040009CA RID: 2506
	[Tooltip("Vehicle light that the shared light is shared with")]
	public VehicleLight sharer;

	// Token: 0x040009CB RID: 2507
	public Material onMaterial;

	// Token: 0x040009CC RID: 2508
	private Material offMaterial;

	// Token: 0x040009CD RID: 2509
	[NonSerialized]
	public bool shattered;
}
